package com.gosuncn.FileCopy;

import java.io.File;
import java.util.ArrayList;

/**
 * 获取文件夹下的所有文件
 * @Author: zhangxiaolong
 * @Date: 2021/8/25 10:01
 */
public class FileUtils {

    File file;
    ArrayList<File> filelist;

    public FileUtils(File file){
        this.file =file;
        this.filelist = new ArrayList<>();
    }


    public void  searchFile(){
        File[] files = file.listFiles();
        for (File file1:files){
            if (file1.isDirectory()){
                file = file1;
                searchFile();
            }else {
                filelist.add(file1);
            }
        }
    }

    public ArrayList<File> getAllFile(){
        searchFile();
        return filelist;
    }



    public static void main(String[] args) {
        String folder = "D:\\dirA";
        File file1 = new File(folder);
        FileUtils fileController = new FileUtils(file1);
//        System.out.println(fileController.countFile());
        System.out.println(fileController.getAllFile());
    }
}
